package cn.zero.letaomallspringboot.mapper;

import cn.zero.letaomallspringboot.entity.Admin;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface AdminMapper {
    List<Admin> selectAll();

    @Select("select uid, password,role from Admin where username = #{username} and enable=1")
    Admin selectByName(@Param("username") String username);

    Admin selectById(Integer id);

    Admin selectByUsernameOrEmail(@Param("username") String username, @Param("email") String email);

    Admin selectByEmailExceptId(@Param("email") String email, @Param("uid") Integer uid);

    void insert(Admin admin);

    void update(Admin admin);

    int deleteById(Integer id);

    List<Admin> search(@Param("username") String username,
                       @Param("email") String email,
                       @Param("role") String role);

    int updatePasswordById(
            @Param("uid") Integer uid,
            @Param("hashed") String hashedPassword,
            @Param("now") Date now
    );
}
